public class State {	
	public int[] board;
	public int[] coinsPerCol;
	public int lastCoinCol;
	public int lastCoinRow;
	public int lastPlayerId = -1;
	public int placedCoins;
	public int rows;
	public int cols;
		
	public State(int cols, int rows, int maxNoOfCoins) {
		this.rows = rows;
		this.cols = cols;
		
		board = new int[maxNoOfCoins];
		coinsPerCol = new int[cols];
		for(int i = 0; i < coinsPerCol.length; i++) {
			coinsPerCol[i] = 0;
		}
	}
	
	public State(State state) {
		rows = state.rows;
		cols = state.cols;
		
		board = new int[state.board.length];
		coinsPerCol = new int[cols];
		System.arraycopy(state.board, 0, board, 0, board.length);
		System.arraycopy(state.coinsPerCol, 0, coinsPerCol, 0, coinsPerCol.length);
		
		lastCoinCol = state.lastCoinCol;
		lastCoinRow = state.lastCoinRow;
		lastPlayerId = state.lastPlayerId;
		placedCoins = state.placedCoins;
	}

	public void insertCoin(int col, int lastPlayerID) {
		this.placedCoins++;
		
		this.lastPlayerId = lastPlayerID;
		this.lastCoinCol = col;
		this.lastCoinRow = coinsPerCol[col]; 

		set(col, coinsPerCol[col], lastPlayerID);
		coinsPerCol[col]++;
	}
	
	public int get(int col, int row) {
		return board[row*cols + col];
	}
	
	public void set(int col, int row, int val) {
		board[row*cols + col] = val;
	}
	
	public void printBoard() {
		for (int col = 0; col < cols; col++)
			System.out.print(coinsPerCol[col]);
		
		System.out.println("\n");
		
		for(int row = rows-1; row >= 0; row--) {
			for(int col = 0; col < cols; col++)
				System.out.print(get(col, row));
			
			System.out.println();
		}
		System.out.println();
	}
}